package com.frinder.robot.strategy.task.convert;

import com.frinder.base.strategy.Strategy;
import com.frinder.robot.strategy.task.convert.biz.ConvertToRobotTransportBackTaskStrategy;
import com.frinder.robot.strategy.task.convert.biz.ConvertToRobotTransportScanBackTaskStrategy;
import com.frinder.robot.strategy.task.convert.biz.ConvertToRobotTransportScanTaskStrategy;
import com.frinder.robot.strategy.task.convert.biz.ConvertToRobotTransportTaskStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @ClassName ConvertToRobotTaskHandler
 * @Description 转化为机器人任务处理方法
 * @Author frinder
 * @Date 2019/10/18 13:57
 * @Verion 1.0
 */
@Slf4j
@Component
public class ConvertToRobotTaskHandler {

    @Autowired
    private ConvertToRobotTransportTaskStrategy convertToRobotTransportTaskStrategy;

    @Autowired
    private ConvertToRobotTransportBackTaskStrategy convertToRobotTransportBackTaskStrategy;

    @Autowired
    private ConvertToRobotTransportScanTaskStrategy convertToRobotTransportScanTaskStrategy;

    @Autowired
    private ConvertToRobotTransportScanBackTaskStrategy convertToRobotTransportScanBackTaskStrategy;

    private ConvertToRobotTaskBaseStrategy convertToRobotTaskBaseStrategy;

    @PostConstruct
    public void post() {
        convertToRobotTaskBaseStrategy = new ConvertToRobotTransportTaskStrategy();
        convertToRobotTaskBaseStrategy
                // 注册策略（去起点-叉货-去目标点-放下货）
                .register(convertToRobotTransportTaskStrategy)
                // 注册策略（去起点-叉货-去目标点-放下货-回原位）
                .register(convertToRobotTransportBackTaskStrategy)
                // 注册策略（去起点-扫码-叉货-去目标点-放下货）
                .register(convertToRobotTransportScanTaskStrategy)
                // 注册策略（去起点-扫码-叉货-去目标点-放下货-回原位）
                .register(convertToRobotTransportScanBackTaskStrategy);
    }

    /**
     * 转化为机器人任务处理方法
     *
     * @param payload
     */
    @Strategy
    public void handle(ConvertToRobotTaskPayload payload) {
        convertToRobotTaskBaseStrategy.handle(payload);
    }
}
